package com.ruoyi.roomNum.controller;

import java.io.InputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.roomNum.domain.RoomNum;
import com.ruoyi.roomNum.service.IRoomNumService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 房间信息管理Controller
 * 
 * @author ruoyi
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/ruoyi/roomNum")
public class RoomNumController extends BaseController
{
    @Autowired
    private IRoomNumService roomNumService;

    /**
     * 导入用户数据
     */
    @Log(title = "客房管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<RoomNum> util = new ExcelUtil<RoomNum>(RoomNum.class);

        InputStream inputStream = file.getInputStream();
        List<RoomNum> roomNumList = util.importExcel(file.getInputStream());
        inputStream.close();

        int count = roomNumService.batchInsertRoomNum(roomNumList);

        String operName = getUsername();

        String message = roomNumService.importRoomNum(roomNumList, updateSupport, operName);
        return success(message);
    }

    /**
     * 获取客房导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<RoomNum> util = new ExcelUtil<RoomNum>(RoomNum.class);
        util.importTemplateExcel(response, "客房数据");
    }

    /**
     * 查询房间信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoomNum roomNum)
    {
        startPage();
        List<RoomNum> list = roomNumService.selectRoomNumList(roomNum);
        return getDataTable(list);
    }

    /**
     * 导出房间信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:export')")
    @Log(title = "房间信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoomNum roomNum)
    {
        List<RoomNum> list = roomNumService.selectRoomNumList(roomNum);
        ExcelUtil<RoomNum> util = new ExcelUtil<RoomNum>(RoomNum.class);
        util.exportExcel(response, list, "房间信息管理数据");
    }

    /**
     * 获取房间信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(roomNumService.selectRoomNumByRoomId(roomId));
    }

    /**
     * 新增房间信息管理
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:add')")
    @Log(title = "房间信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomNum roomNum)
    {
        return toAjax(roomNumService.insertRoomNum(roomNum));
    }

    /**
     * 修改房间信息管理
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:edit')")
    @Log(title = "房间信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomNum roomNum)
    {
        return toAjax(roomNumService.updateRoomNum(roomNum));
    }

    /**
     * 删除房间信息管理
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:roomNum:remove')")
    @Log(title = "房间信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(roomNumService.deleteRoomNumByRoomIds(roomIds));
    }
}
